package view;

import android.view.View;

import androidx.viewpager.widget.ViewPager;

import java.lang.reflect.Field;

public class ViewPagerUtils {
    public static View getCurrentView(ViewPager viewPager) {
        final int currentItem = viewPager.getCurrentItem();
        for (int i = 0; i < viewPager.getChildCount(); i++) {
            final View child = viewPager.getChildAt(i);
            final ViewPager.LayoutParams layoutParams = (ViewPager.LayoutParams) child.getLayoutParams();
            Class<? extends ViewPager.LayoutParams> aClass = layoutParams.getClass();
            Field position = null;
            try {
                position = aClass.getField("position");
                if (!layoutParams.isDecor && currentItem == (Integer) (position.get(layoutParams))) {
                    return child;
                }
            } catch (Exception e) {
                e.printStackTrace();
            }

        }
        return null;
    }

}
